package com.goushu.mapper;

import com.goushu.pojo.Cart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CartMapper {
    
    @Select("select cart.id, cart.c_id, cart.b_id, img, name, price, cart.count, cart.selected from cart left outer join customer on c_id=customer.id left outer join book on book.id=b_id where customer.id=#{cId};")
    List<Cart> listCart(Integer cId);

    @Insert("insert into cart (b_id, c_id, count, update_time, selected) values (#{id}, #{cId}, #{count}, now(), true) ")
    void addCart(Integer id, Integer count, Integer cId);

    @Select("select * from cart where c_id=#{cId} and b_id=#{id}")
    Cart checkCartExist(Integer id, Integer cId);

    @Update("update cart set count=#{count}, selected=#{selected}, update_time=now() where id=#{id}")
    void modifyCart(Cart cart);

    @Delete("delete from cart where id=#{id}")
    void deleteCart(Integer id);

    @Update("update cart set count=#{count}, update_time=now() where c_id=#{cId} and b_id=#{id}")
    void updateCount(Integer id, Integer count, Integer cId);

    @Delete("delete from cart where b_id=#{bId} and c_id=#{cId}")
    void deleteCartByBId(Integer bId, Integer cId);
}
